package com.gxuwz.medical.domain.user;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.sql.*;

import com.gxuwz.medical.dao.UserDao;
import com.gxuwz.medical.database.DbUtil;
import com.gxuwz.medical.domain.role.Role;
import com.gxuwz.medical.vo.PageBean;

/**
 * 鐢ㄦ埛淇℃伅瀹炰綋绫�
 * 
 * @author 婕旂ず
 * 
 */
public class User {

	private String userid;

	private String pwd;

	private String fullName;

	private Set<Role> roles = new HashSet();

	private UserDao userdao = new UserDao();

	public void addRole(String[] roleid) {
		for (int i = 0; i < roleid.length; i++) {
			Role role = new Role();
			role.setRoleid(roleid[i]);
			roles.add(role);
		}

	}

	public void addRole(Role role) {
		roles.add(role);
	}

	public User login(String userid, String pwd) throws SQLException {
		return userdao.login(userid, pwd);
	}

	public void add() throws SQLException {
		userdao.add(this);
	}

	public void delete(String userid) throws SQLException {
		userdao.delete(userid);
	}

	public User query() throws SQLException {
		User u = new User();
		u = userdao.query(userid);
		return u;
	}

	public PageBean queryAll(int page,int size) throws SQLException {
		return userdao.queryAll(page,size);
	}
	
	public List<User> queryAll() throws SQLException {
		return userdao.queryAll();
	}

	public void update() throws SQLException {
		userdao.update(this);
	}

	public User() {
		super();
	}

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}

	public String getFullName() {
		return fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

}
